//
//  MYComposePhotosView.m
//  奇闻
//
//  Created by 似水灵修 on 14-12-1.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYComposePhotosView.h"

@implementation MYComposePhotosView
- (NSMutableArray *)images
{
    if (nil == _images) {
        _images = [NSMutableArray array];
    }
    return _images;
}
- (void)addImage:(UIImage *)image
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    
    [self addSubview:imageView];
    // 添加到数组
    [self.images addObject:image];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    NSUInteger count = self.subviews.count;
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat col = 0;
    CGFloat row = 0;
    CGFloat margin = 10;
    int cols = 3;
    CGFloat wh = (self.width - (cols - 1) * margin) / cols;
    for (NSUInteger i = 0; i < count; i++) {
        col = i % cols;
        row = i / cols;
        x = col * (wh + margin);
        y = row * (wh + margin);
        UIImageView *imagV = self.subviews[i];
        imagV.frame = CGRectMake(x, y, wh, wh);
    }
}
@end
